<template>
  <div>
    <a v-print='printObjs' style='color: #fff'>确定</a>
    <div v-show='false'>
      <div id='printMes'>
        <div style="page-break-after:always">
          <p>
            <span>{{ moment(prinForm.date).format('YYYY/MM/DD') }}</span><span style='margin-left: 10px'>{{
              prinForm.Controlsname.toString() }}</span>
          </p>
          <div class='title'>{{ prinForm.title }}</div>
          <div class="print-content">
            <div class='user-codes'>
              <div v-for='(item, index) in prinForm.Userlist' :key='index' class='code-item'>
                <vue-qr :text="JSON.stringify({ userid: item.userid, EntityType: 'printTask' })" :size='80'
                  :margin='0'></vue-qr>
                <div class='nameCol'>{{ item.realname }}</div>
              </div>
            </div>
          </div>
        </div>

        <div style="page-break-after:always">
          <p>
            <span>{{ moment(prinForm.date).format('YYYY/MM/DD') }}</span><span style='margin-left: 10px'>{{
              prinForm.Controlsname.toString() }}</span>
          </p>
          <div class='title'>报工卡-产量</div>
          <div class='print-content'>
            <div class='outputTable'>
              <div class="innerFlexBox">
                <svg id='barcode0' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode1' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode2' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode3' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode4' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode5' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode6' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode7' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode8' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcode9' class='bd'></svg>
              </div>
              <div class="innerFlexBox">
                <svg id='barcodeDot' class='bd'></svg>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import JsBarcode from 'jsbarcode'
import print from 'vue-print-nb'
import moment from 'moment'
import vueQr from 'vue-qr'
import { subStrText } from '@/utils/util'

export default {
  props: {
    id: {
      type: String,
      default: ''
    },
    prinForm: {
      type: Object,
      default: {
        title: '',
        Controlsname: ''
      }
    }
  },
  directives: {
    print
  },
  data() {
    return {
      subStrText,
      moment,
      printObjs: {
        id: 'printMes',
        clickMounted(vue) {
          vue.$emit('changePrint')
        }
      },
      detailData: [],
      realname: '',
      date: ''
    }
  },
  components: { vueQr },
  mounted() {
    this.generateBarcode()
  },
  methods: {
    generateBarcode() {
      const options = {
        format: 'CODE128',
        lineColor: '#000',
        width: 2,
        height: 50,
        fontOptions: "bold",
        displayValue: true
      };

      const ids = ['barcode0', 'barcode1', 'barcode2', 'barcode3', 'barcode4', 'barcode5', 'barcode6', 'barcode7', 'barcode8', 'barcode9', 'barcodeDot'];
      const values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'];

      ids.forEach((id, index) => {
        JsBarcode(`#${id}`, values[index], options);
      });
    }
  }
}
</script>

<style lang='less' scoped>
.code-item {
  width: 100mm;
  height: 50mm;
  border: solid 1px #eee;
  position: relative;
  font-size: 12px;
}

@media print {
  @page {
    /* 纵向打印 */
    size: auto;
    /* 去掉页眉页脚*/
    margin-top: 0;
    margin-bottom: 0;
  }
}

.title {
  text-align: center;
  font-size: 20px;
}

.nameCol {
  font-size: 16px;
  text-align: center;
}

.print-content {
  border: 1px solid #666;
  padding: 10px;
  width: 100%;

  .outputTable {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
    height: 90vh;
    box-sizing: border-box;
  }
    .innerFlexBox {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
}

.bd {
  border: 1px solid #666;
  padding: 5px 0 0 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.user-codes {
  // border: 1px solid #666;
  height: 90vh;
  padding: 5px;
  flex: 1;
  margin: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .code-item {
    width: 22%;
    height: 120px;
    display: flex;
    flex-direction: column;
  }
}
</style>
